package cn.howxu.yichen_ovo.client.event;

import cn.howxu.yichen_ovo.YiChenOVO;
import cn.howxu.yichen_ovo.client.util.ColorText;
import cn.howxu.yichen_ovo.common.item.Sword;
import net.minecraft.ChatFormatting;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;

/**
 * @description: TODO
 * @author: HowXu
 * @date: 2025/9/22 17:38
 */
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = YiChenOVO.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class ToolTipEvent {

    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent
    public static void onTooltip(ItemTooltipEvent event) {
        if (event.getItemStack().getItem() instanceof Sword) {
            int sz = event.getToolTip().size();
            for (int x = 0; x < sz; x++) {
                if (event.getToolTip().get(x).getString().contains(I18n.get("attribute.name.generic.attack_damage"))) {
                    StringBuilder builder = new StringBuilder(ColorText.makeFabulous(I18n.get("tooltip.infinity")));
                    builder.append(" ");
                    builder.append(ColorText.makeGreen(I18n.get("attribute.name.generic.attack_damage")));
                    event.getToolTip().set(x, Component.literal(builder.toString()));
                    return;
                }
            }
        }
        
    }
}
